﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GsnHelper;
using Microsoft.Data.Edm;
using PetaPoco;
namespace ZhongheCms.Models
{
    public partial class GswTblMember
    {
        [ResultColumn]
        public List<GswTblBaseInfo> BaseInfos { get; set; }
        [ResultColumn]
        public Page<GswTblMemberPoint>  MemberPoints { get; set; }
        [ResultColumn]
        public Page<GswViewJobWorkAll> JobWorkAlls { get; set; }

        [ResultColumn]
        public List<GswViewJobWorkAll> JobWorkAllp { get; set; }

          [ResultColumn]
        public List<GswTblMemberTime> MemberTimes { get; set; }
          [ResultColumn]
        public Page<GswTblMemberHelp> MemberHelps { get; set; }
        [ResultColumn]
        public List<GswTblJobInfo> JobInfos { get; set; }
        [ResultColumn]
        public GswTblJobInfo JobInfo { get; set; }

        
         public static Page<GswTblMember> GetMembers(string sdate, string edate, string keywords,int cusid,int pageIndex)
        {
            var sql = "select * from GswTblMember where ParentId=" + cusid;
            int flag = 0;
            var q = new GswTblMember();
            //q.MemberUserName
            if (InputValid.IsDate(sdate))
            {
                flag = 1;
                sql += " and RegDate>='" + sdate + "'";
            }
            if (InputValid.IsDate(edate))
            {
                flag = 1;
                sql += " and RegDate<='" + edate + "'";
            }
            if (!string.IsNullOrEmpty(keywords))
            {
                flag = 1;
                sql += " and (MemberName like '%" + keywords + "%' or MemberNickname like '%" + keywords + "%' or MemberUserName  like '%" + keywords + "%')";

            }
            if(flag==0)
                sql += " and RegDate>='" + DateTime.Today.AddDays(-30).ToShortDateString() + "'";
            sql += " order by id desc";
             var db = new ZhongheRepo();

             var qry = db.Page<GswTblMember>(pageIndex, 20, sql);
            return qry;

        }
    }

    public partial class GswTblMemberHelp
    {
        [ResultColumn]
        public GswTblMember MemberInfo { get; set; }

    }
}